Todo:
organize the program by parts (well defined parts)


Bellow it is an incomplete and non-updated description about the BMD/BDL file format

POINTER TABLE UPDATED FOR:
- BTP
- ...


BDL DEFINITIONS:

- BMD/BDL file: JSYSTEM file that appears in Super Mario Galaxy (and other Wii games) which
            purpose is to store 3D model data.
- BMD/BDL start section: first 32 bytes of a BDL file containing the BDL file start, the BDL file
                     size (in bytes), the section count and 16 bytes that are unknown.
- BMD/BDL file start: first 4 bytes of the BMD/BDL file that contain a char[4] array unique BMD/BDL files
                  ("J3D2").
- BMD/BDL ID: next to BMD/BDL file start. Block of the BMD/BDL file that contains a char[4] array unique BMD/BDL files
              ("bdl4" for BDL, "bmd3" for BMD).
- INF1 section: first section of the BMD/BDL. Starts with "INF1" and next to it an u32 with the section size in bytes.
- VTX1 section: second section of the BMD/BDL. Starts with "VTX1" and next to it an u32 with the section size in bytes.
- EVP1 section: third section of the BMD/BDL. Starts with "EVP1" and next to it an u32 with the section size in bytes.
- DRW1 section: fourth section of the BMD/BDL. Starts with "DRW1" and next to it an u32 with the section size in bytes.
- JNT1 section: fifth section of the BMD/BDL. Starts with "JNT1" and next to it an u32 with the section size in bytes.
- SHP1 section: sixth section of the BMD/BDL. Starts with "SHP1" and next to it an u32 with the section size in bytes.
- MAT3 section: seventh section of the BMD/BDL. Starts with "MAT3" and next to it an u32 with the section size in bytes.
                Contains the model's material information.
- MDL3 section: eighth section of the BDL. Starts with "MDL3" and next to it an u32 with the section size in bytes.
                Not present on BMD.
- TEX1 section: nineth section of the BDL (eighth of the BMD, and last one in both). 
                Starts with "TEX1" and next to it an u32 with the section size in bytes.
                Contains the model's textures data.
- Material Name Table: table containing the number of materials on the BMD/BDL, specific information
                       of each material name and the name of each material. The order of the materials
                       starting with 0 is their index number on the BMD/BDL model.
- Texture Name Table: table containing the number of textures on the BMD/BDL, specific information
                      of each texture name and the name of each texture. Sometimes contains repeated textures
                      (unknown reason). The order of the textures starting with 0 is their index
                      number on the BMD/BDL model.
- String weight: defined way to calculate the numeric value of a string (at least on texture/material
                 name strings). Using the ASCII character table and the length of the string
                 (without counting the null character) the calculation process goes as follows
                 (reading chars from left to right):
                 
                 STRING WEIGHT = [FIRST CHAR VALUE] * (3^(STRING LENGTH - 1)) 
                                 + [SECOND CHAR VALUE] * (3^(STRING LENGTH - 2))
                                 + [THIRD CHAR VALUE] * (3^(STRING LENGTH - 3))
                                 + ...
                                 + [LAST CHAR VALUE] * (3^(0))
                                 
                 NOTE: the string weight is stored in a 2 byte block so when a string weight
                 is greater than 65535 the number gets truncated to the 16 bits that the 2 byte
                 block can hold (the 16 ones that show when reading the string from right to left).
                 
                 Example:
                 
                 String: "Body1_v"
                 String weight: 87298
                 Binary rep of string weight: 010101010100000010 (18 bits)
                 Bits stored in the 2 bytes:    0101010100000010 (16 bits)
                 Truncated String weight stored in the 2 bytes: 21762


BDL POINTER TABLE:

POS   --> Pointer position on pointer table
DESC  --> Description of what the pointer is set to point

There will be a total of ?? pointers for the important sections on a BDL file.
"$$" will be used to indicate the start of a section
"//" will be used in case there is additional information related to a pointer
"##" will be used to specify skipping blocks of information (BMD/BDLs are huge)

POS DESC


$$  (COMPLETE)
0   BMD/BDL file start (char[4])
1   BMD/BDL ID (char[4])
2   BMD/BDL file size in bytes (u32)
3   BMD/BDL section count (u32 - always 00 00 00 09? - for BMD: always 00 00 00 08?)
4   Unknown 1 (16 bytes - always 53 56 52 33 FF FF FF FF FF FF FF FF FF FF FF FF? SMG specific BDLs)


$$
5   INF1 section start (char[4])
6   INF1 section size in bytes (u32)

##  skip to next section


$$
7   VTX1 section start (char[4])
8   VTX1 section size in bytes (u32)

##  skip to next section


$$
9   EVP1 section start (char[4])
10  EVP1 section size in bytes (u32)

##  skip to next section


$$
11  DRW1 section start (char[4])
12  DRW1 section size in bytes (u32)

##  skip to next section


$$
13  JNT1 section start (char[4])
14  JNT1 section size in bytes (u32)

##  skip to next section


$$
15  SHP1 section start (char[4])
16  SHP1 section size in bytes (u32)

##  skip to next section


$$
17  MAT3 section start (char[4])
18  MAT3 section size in bytes (u32)
19  Number of materials used on the BMD/BDL (u16)

##  skip 10 bytes of information

20  Material Name Table offset with respect to MAT3 section start (u32)

##  jump to Material Name Table start

21  Material Name Table start
//  Number of materials used on the BMD/BDL again (u16)

22  Unknown (2 bytes - always FF FF?)

23  Information specific to each material on the Material Name Table
//  next (Number of materials * 4) bytes are:
//  - String weight for the First material name (index 0) in the Material Name Table (u16)
//  - Offset position of First material name with respect to the Material Name Table start (u16 - POS 21)
//  ... (repeat for Second, Third... given the number of materials on the BMD/BDL)

24  Material string names start
//  contains (Number of materials) strings (null terminated).

##  skip to next section (TEX1 section if BMD, MDL3 section if BDL)


$$
25  MDL3 section start (char[4])
26  MDL3 section size in bytes (u32)

##  skip to next section (END OF FILE if BMD, TEX1 section if BDL)


$$  (COMPLETE)
27  TEX1 section start (char[4])
28  TEX1 section size in bytes (u32)
29  Number of textures used on the BMD/BDL (u16)
30  Unknown 3 (2 bytes)
31  BTI header list offset with respect to TEX1 section start (u32)
32  Texture Name Table offset with respect to TEX1 section start (u32)
33  Padding 1 (until the nearest address that is multiple of 32)
34  BTI header list start (32 * number of textures bytes long)
35  BTI data list start (has to be a multiple of 32 at least)
36  Texture Name Table start
//  Number of textures used on the BMD/BDL again (u16)

37  Unknown 4 (2 bytes - always FF FF?)

38  Information specific to each texture on the Texture Name Table
//  next (Number of textures * 4) bytes are:
//  - String weight for the First texture name (index 0) in the Texture Name Table (2 bytes)
//  - Offset position of First texture name with respect to the Texture Name Table start (u16 - POS 36)
//  ... (repeat for Second, Third... given the number of textures on the BMD/BDL)

39  Texture string names start
//  contains (Number of textures) strings (null terminated).

40  Padding 2 (until the nearest address that is multiple of 32)
41  END OF FILE 
